const { ccclass, property } = cc._decorator;

@ccclass
export default class Dictionary {
private _length: number;
private _container: Object;

constructor() {
    this._length = 0;
    this._container = {};
}

get container() {
    return this._container;
}

get length() {
    return this._length;
}

add(key, value) {
    if (!this.containsKey(key)) {
        this._length++;
    }
    this._container[key] = value;
}

get(key) {
    return this._container[key];
}

reset(key, value) {
    if (this.containsKey(key)) {
        this._container[key] = value;
    } else {
        console.warn(`Dictionary: warning you reset a non-existent key(${key})`);
    }
}

containsKey(key) {
    return this._container.hasOwnProperty(key);
}

remove(key) {
    if (this.containsKey(key)) {
        this._container[key] = null;
        delete this._container[key];
        this._length--;
    }
}

clear() {
    this._length = 0;
    this._container = {};
}
}